package com.hc.web.struts.action.bbs;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

import com.hc.entity.bbs.Topic;
import com.hc.web.service.bbs.ClubService;
import org.springframework.security.userdetails.jdbc.JdbcDaoImpl;

public class TopicAction extends ActionSupport {
	private Topic topic;
	private Integer topicId;
	private Integer parentId;
    private ClubService clubService;
    
    public Topic getTopic() {
		return topic;
	}
    
    public void setTopic(Topic topic) {
    	this.topic = topic;
    }
    
	public void setClubService(ClubService clubService) {
    	this.clubService = clubService;
    }
	
	public String showTopic() {
		
		topic = clubService.getTopicByTopicId(topicId);
		if (topic != null) {
			return "show";
		} else {
			return "error";
		}
	}
	
	public String newTopic() {
		return "new";
	}
	
	public String saveTopic() {
		if (topic != null && topic.getTopicContent().trim().length() > 0) {
			clubService.saveTopic(topic);
			return "save"; 
		} else {
			return "error";
		}
	}
	
	public Integer getTopicId() {
		return topicId;
	}

	public Integer getParentId() {
		return parentId;
	}
	
	public void setTopicId(Integer topicId) {
		this.topicId = topicId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}
}
